package com.yunquan.ohana.ui.guide

import android.os.Bundle
import android.view.View
import androidx.viewpager2.widget.ViewPager2
import com.yunquan.ohana.BR
import com.yunquan.ohana.R
import com.yunquan.ohana.base.ui.BaseActivity
import com.yunquan.ohana.databinding.ActivityGuideBinding
import com.yunquan.ohana.ui.guide.adapter.GuideAdapter
import com.yunquan.ohana.ui.main.MainActivity

class GuideActivity : BaseActivity<ActivityGuideBinding, GuideViewModel>() {

    private var mCurrentIndex = 0

    override fun initContentView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_guide
    }

    override fun initVariableId(): Int {
        return BR.guideViewModel
    }

    override fun initParam() {
        super.initParam()
        window.statusBarColor = resources.getColor(R.color.white)
        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
    }

    override fun initData(savedInstanceState: Bundle?) {
        super.initData(savedInstanceState)
        val adapter = GuideAdapter()
        adapter.setOnSkipClickListener {
            startActivity(MainActivity::class.java)
            finish()
        }
        adapter.setOnNextClickListener {
            mCurrentIndex++
            if (mCurrentIndex > 2) {
                startActivity(MainActivity::class.java)
                finish()
            } else {
                binding!!.viewPager.setCurrentItem(mCurrentIndex, true)
            }
        }
        binding!!.viewPager.adapter = adapter
        binding!!.viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                mCurrentIndex = position
            }
        })
    }
}